package com.zzu.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.zzu.R;
import com.zzu.model.bean.DLS;
import com.zzu.utils.ChangeActivity;

import java.util.List;

/**
 * @description:
 * @author: bytedance
 * @date: 2021-05-08 15:52
 */
public class ThreeAdapter extends RecyclerView.Adapter<ThreeAdapter.ViewHolder> {

    private static final String TAG = ThreeAdapter.class.getName();
    private Context mContext;
    private List<DLS> datas;

    public ThreeAdapter(Context context, List<DLS> datas) {
        mContext = context;
        this.datas = datas;
        Log.i(TAG,"初始化的数据为"+datas);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.item_three, null);
        return new ViewHolder(view);
    }

    //进行数据的绑定
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        //1.根据位置得到对应的Bean对象
        DLS dls = datas.get(position);
        Log.i(TAG,"数据绑定"+dls);
        //2.设置数据
        holder.tv_three_packageId.setText(dls.getPackageId());
        holder.tv_three_sender.setText(dls.getSender());
        holder.tv_three_submitTime.setText(dls.getSubmitTime());
        holder.tv_three_senderTel.setText(dls.getSenderTel());
        holder.tv_three_senderAddress.setText(dls.getSenderAddr());

    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_three_packageId;
        TextView tv_three_sender;
        TextView tv_three_submitTime;
        TextView tv_three_senderTel;
        TextView tv_three_senderAddress;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_three_packageId = itemView.findViewById(R.id.tv_three_packageId);
            tv_three_sender = itemView.findViewById(R.id.tv_three_sender);
            tv_three_submitTime = itemView.findViewById(R.id.tv_three_submitTime);
            tv_three_senderTel = itemView.findViewById(R.id.tv_three_senderTel);
            tv_three_senderAddress = itemView.findViewById(R.id.tv_three_senderAddress);

            itemView.setOnClickListener(new View.OnClickListener(){

                @Override
                public void onClick(View v) {
//                    Log.i(TAG,"包裹id为："+datas.get(getLayoutPosition()).getPackageId()+"包裹的位置"+getLayoutPosition());
                    String packageId = datas.get(getLayoutPosition()).getPackageId();
                    //进行页面跳转
                    ChangeActivity.ChangeExpressInfo(mContext,packageId);
                    //刷新数据
                    notifyDataSetChanged();
                }
            });
        }
    }



}
